#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 10010;

typedef long long ll;

int n,a[MAXN],ltag[MAXN<<2],rtag[MAXN<<2],tot;
ll val[MAXN<<2],sum[MAXN<<2],num[MAXN<<2],ans;

struct line{
	int x1,x2,y,tag;
	bool operator < (const line &b) const{
		return y ^ b.y ? y < b.y : tag > b.tag;
	}
}l[MAXN];

void pushup(int o,int l,int r){
	if(sum[o]){
		ltag[o] = rtag[o] = 1;
		val[o] = a[r+1] - a[l];
		num[o] = 1;
	}
	else if(l == r){
		ltag[o] = rtag[o] = 0;
		val[o] = 0;
		num[o] = 0;
	}
	else{
		val[o] = val[o<<1] + val[o<<1|1];
		num[o] = num[o<<1] + num[o<<1|1];
		if(rtag[o<<1] && ltag[o<<1|1]) num[o]--;
		ltag[o] = ltag[o<<1];
		rtag[o] = rtag[o<<1|1];
	}
}

void upd(int xl,int xr,int v,int o = 1,int l = 1,int r = tot-1){
//	cout << xl<<".."<<xr<<".."<<o<<".."<<l<<".."<<r<<endl;
	if(xl == l && xr == r){
		sum[o] += v;
		pushup(o,l,r);
		return;
	}
	int mid = l+r>>1;
	if(xr <= mid) upd(xl,xr,v,o<<1,l,mid);
	else if(xl > mid) upd(xl,xr,v,o<<1|1,mid+1,r);
	else upd(xl,mid,v,o<<1,l,mid),upd(mid+1,xr,v,o<<1|1,mid+1,r);
	pushup(o,l,r);
}

int main (){
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		int x1,x2,y1,y2;
		scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
		l[(i<<1)-1] = (line){x1,x2,y1,1};
		l[i<<1] = (line){x1,x2,y2,-1};
		a[(i<<1)-1] = x1; a[i<<1] = x2;
	}
	n<<=1;
	sort(a+1,a+n+1); sort(l+1,l+n+1);
	tot = unique(a+1,a+n+1)-a-1;
	for(int i = 1;i <= n;i++){
		ll tmp = val[1];
		l[i].x1 = lower_bound(a+1,a+tot+1,l[i].x1)-a;
		l[i].x2 = lower_bound(a+1,a+tot+1,l[i].x2)-a;
		if(l[i].x1 != l[i].x2) {
			upd(l[i].x1,l[i].x2-1,l[i].tag);
		}
		ll delta1 = val[1] - tmp,delta2 = num[1];
		if(delta1 < 0) delta1 = -delta1;
		ans += delta1;
		ans += delta2 * 2 * (l[i+1].y - l[i].y);
	}
	printf("%lld\n",ans);
	return 0;
}
